<template>
    <a-form ref="formRef" :model="formData">
        <a-form-item field="name" label="名称" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.name" placeholder="请输入名称"></a-input>
        </a-form-item>
        <a-form-item field="cover" label="封面图片" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <ma-upload v-model="formData.cover" title="封面图片" type="image"></ma-upload>
        </a-form-item>
        <a-form-item field="price" label="价格" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.price" placeholder="请输入价格"></a-input>
        </a-form-item>
        <a-form-item field="issue" label="本次发行" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input-number v-model="formData.issue" placeholder="请输入本次发行" />
        </a-form-item>
        <a-form-item field="can_sell" label="是否可寄售" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-radio-group v-model="formData.can_sell">
                <a-radio :value="0">可以</a-radio>
                <a-radio :value="1">不可以</a-radio>
            </a-radio-group>
        </a-form-item>
        <a-form-item field="synopsis" label="简介" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <a-input v-model="formData.synopsis" placeholder="请输入简介"></a-input>
        </a-form-item>
        <a-form-item field="content" label="详情" label-col-flex="auto" :label-col-style="{ width: '85px' }">
            <MaEditor v-model="formData.content"></MaEditor>
        </a-form-item>
    </a-form>
</template>

<script setup>
import { ref } from "vue";
import request from '@/api/product'
import { Message } from "@arco-design/web-vue";
const emit = defineEmits(["refreshList"]);

const props = defineProps({
    id: [String, Number]
});
const formData = ref({});

const getDeta = async () => {
    let { data } = await request.get_deta(props.id);
    formData.value = data.data;
};
props.id ? getDeta() : "";

const submit = async () => {
    await request.save(formData.value);
    Message.success("保存成功");
    setTimeout(() => emit("refreshList"), 500);
};
defineExpose({ submit });
</script>